package com.jbm.enterapplication.loadpage.presenter

import android.Manifest
import android.content.Context
import android.os.Build
import android.support.annotation.RequiresApi
import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.loadpage.mode.Load_Mode_Pager
import com.jbm.enterapplication.loadpage.view.Load_view_Pager_In

/**
 * Created by 家帮忙 on 2017/9/4.
 */
class Load_Present_page : Load_Present_Page_In {
    override fun getConnsServer() {

    }


    override fun getVisionCode(context: Context) {
        loadmodepager?.getVisionCode(context, object : InterfaceMa<String> {
            @RequiresApi(Build.VERSION_CODES.M)
            override fun onSuccess(t: String, boolean: Boolean) {
                if (Build.VERSION.SDK_INT >= 23) {

                    val i = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    if (i == 0) {
                        loagviewpager?.Permissions(t, boolean, 1)
                    } else {
                        loagviewpager?.Permissions(t, boolean, 2)
                    } }else{
                    loagviewpager?.Permissions(t, boolean, 1)
                }



            }

            override fun setError(err: String, boolean: Boolean) {
                if (err.equals("1")) {//错误
                    loagviewpager?.Permissions(err, boolean, 3)
                } else if (err.equals("2")) {//必须更新
                    loagviewpager?.finishs()
                }

            }

        })
    }


    var loagviewpager: Load_view_Pager_In? = null
    var context: Context? = null
    var loadmodepager: Load_Mode_Pager? = null

    constructor(loagviewpager: Load_view_Pager_In?, context: Context?) {
        this.loagviewpager = loagviewpager
        this.context = context
        loadmodepager = Load_Mode_Pager()
    }


}